<?php
//	file:  Api.class.php
//	time:  Jan 12, 2016 11:39:27 AM

namespace Have\Api;
define('HUC_CLIENT_PATH', dirname(dirname(__FILE__)));

// 载入配置文件
require_cache(HUC_CLIENT_PATH . '/Conf/uconfig.php');

// 载入函数库文件
// require_cache(HUC_CLIENT_PATH . '/Common/function.php');

abstract class Api {
    /**
     * API 调用模型实例
     */
    protected $model;
    
    protected $M;
    
    public function __construct(){
        defined('HUC_APP_ID') || throw_exception('HUC 配置错误:缺少HUC_APP_ID');
        defined('HUC_API_TYPE') || throw_exception('HUC 配置错误：缺少HUC_API_TYPE');
        defined('HUC_AUTH_KEY') || throw_exception('HUC 配置错误: 缺少HUC_AUTH_KEY');
        defined('HUC_DB_DSN') || throw_exception('HUC配置配置错误: 缺HUC_DB_DSN');
        defined('HUC_TABLE_PREFIX') || throw_exception('HUC配置错误: 缺少HUC_TABLE_PREFIX');
        if (HUC_API_TYPE != 'Model' && HUC_API_TYPE != 'Service') {
            throw_exception('HUC配置错误: HUC_API_TYPE只有为Model或Service');
        }
        if (HUC_API_TYPE == 'Service' && HUC_AUTH_KEY == '') {
            throw_exception('HUC配置错误: Service方式调用Api时HUC_AUTH_KEY不能为空');
        }
        if (HUC_API_TYPE == 'Model' && HUC_DB_DSN == '') {
            throw_exception('HUC配置错误: Model 方式调用Api时HUC_DB_DSN不能为空');
        }
        
        $this->_init();
    }
    
    /**
     * 抽象方法，用于设置模型实例
     */
    abstract protected function _init();
}
	
?>